#include "zoo.h"
#include <iostream>

bool Zoo::addAnimal(Animal* animal) {
	int ret = false;
	std::unique_ptr<Animal> an;
	if (animal) {
		switch (animal->getSpeciesId()) {
			case Species::DOG: {
				Dog* dog = dynamic_cast<Dog*>(animal);
				if (dog) {
					an = std::make_unique<Dog>(*dog);
					ret = true;
				}
			} break;
			case Species::CAT: {
				Cat* cat = dynamic_cast<Cat*>(animal);
				if (cat) {
					an = std::make_unique<Cat>(*cat);
					ret = true;
				}
			} break;
			case Species::TIGER: {
			} break;
			case Species::ELEPHANT: {
			} break;
			default:
				break;
		}
	}
	if (ret) animals.push_back(std::move(an));
	return ret;
}

void Zoo::show() const {
	if (animals.size() == 0) {
		printf("[%s]\n", "(null)");
		return;
	}

	printf("[%s] Zoo\n", name.c_str());
	for (auto& animal : animals) {
		std::cout << animal->toString() << "\n";
		std::cout << animal->say() << "\n";
	}
}

Zoo::Zoo(const std::string& name) : name(name) {}
